package leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 描述:111. 二叉树的最小深度
 *
 * @author Madison You
 * @created 10:01
 */
public class Easy_111_MinDepth {
    public static void main(String[] args) {

    }

    public int minDepth(TreeNode root) {
        Queue<TreeNode> queue = new LinkedBlockingQueue<>();
        if (root == null) return 0;
        queue.offer(root);
        int j = 0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode node = queue.poll();
                j++;
                if (node.left == null && node.right == null) {
                    return j;
                }
                if (node.left != null) {
                    queue.offer(node.left);
                }
                if (node.right != null) {
                    queue.offer(node.right);
                }
            }
        }
        return j;
    }
}
